<template>
  <div>
    <!-- 显示消息：{{ mes }} -->
    <!-- <el-input v-model="sendsms"></el-input> -->
    <!-- <el-button @click="">submit</el-button> -->

    <template>
      <el-table :data="mes" style="width: 100%">
        <el-table-column prop="id" label="ID">
        </el-table-column>

        <el-table-column prop="name" label="名称">
        </el-table-column>

        <el-table-column prop="wen" label="温度">
        </el-table-column>

        <el-table-column prop="max" label="最高温度"> 
        </el-table-column>

        <el-table-column prop="min" label="最低温度">
        </el-table-column>

        <el-table-column prop="status" label="状态" :formatter="datas">
        </el-table-column>

        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row.id)" type="text" size="small">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>

    <el-dialog title="添加温度" :visible.sync="dialogTableVisible">
        
        <el-form :model="ruleForm" status-icon class="demo-ruleForm">
        <el-form-item label="年龄" prop="age">
            <el-input v-model.number="ruleForm.wen"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm">提交</el-button>
        </el-form-item>
        </el-form>
        
        

    </el-dialog>

  </div>
</template>

<script>
export default {
  data() {
    return {
      mes: "",
      ws: "",
      sendsms: "",
        dialogTableVisible:false,
      ruleForm:{
        wen:"",
      },
      id:0
    };
  },
  methods: {
    submitForm(){
        this.axios.get('/addredis/?id=' + this.id + "&wen=" + this.ruleForm.wen).then(resp=>{
            console.log(resp)
            alert(resp)
        })
    },
    handleClick(id){
        alert(id)
        this.dialogTableVisible = true
        this.id = id
    },
    initWebsocket() {
      this.ws = new WebSocket("ws://localhost:8000/webce/?id=1");
      this.ws.onopen = function () {
        // alert("success")
      };
      this.ws.onmessage = (data) => {
        this.mes = JSON.parse(data.data);
      };

      this.ws.onclose = function () {
        // alert("close")
      };
    },
    getdapeng() {
      this.axios.get("getda/?id=1").then((resp) => {
      });
    },
    datas(row) {
      if (row.status == 0) {
        return "正常";
      } else {
        return "请尽快修理";
      }
    },
    // send() {
    //   this.ws.send(this.sendsms);
    // },
  },
  mounted() {
    this.initWebsocket();
    this.getdapeng();
  },
};
</script>

<style>
</style>
